﻿<script type="text/javascript">
    var Materials = new Array(); //用于存放勾选任务行的行数据的数组---push（row）


    function EUIcombobox(jqS, o) {
        $.ajax({
            type: "POST",
            async: false,
            url: o.url,
            dataType: "JSON",
            success: function (data1, textStatus, jqXHR) {
                o.data = o.OneOption.concat(data1);
                delete o.url;
                delete o.OneOption;
                $(jqS).combobox(o);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("获取字典数据失败！可能是已经超时，请重新登录！");
            }
        });
    }

    function initPickTaskGrid() {


        $('#txtStartTime').datetimebox({
             value: $.GetNDayAgo(59),
          //  value: "2017-03-05 00:00:00",
            required: true,
           // readonly: true

        }); //默认取昨天任务的。

        $('#txtEndTime').datetimebox({
            value: $.GetToday(),
            // value: "2017-03-20 00:00:00",
            required: true,
           // readonly: true


        });  //默认取今天现在。

        zz();
        PickTaskGrid();

    } //初始化结束

    //当开始时间和结束时间的值改变的时候，触发去查询所有中不同车辆

    function zz() {

        var starttime = $('#txtStartTime').datetimebox("getValue");
        var endtime = $('#txtEndTime').datetimebox("getValue");

        var urlstr1 = '@Url.Content("~/DD/DriverReport/GetAmbulance?starttime=")' + starttime + "&endtime=" + endtime + "&DworkID=" + DworkID;
        //2016-6-7 zch
        // EUIcombobox("#txtAmbulance", {
        $("#txtAmbulance").combobox({
            url: urlstr1,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            required: true,
            readonly: true,
            //OneOption: [{
            //    ID: "",
            //    Name: "--请选择--"
            //}],
            onLoadSuccess: function (data) {
                if (data[1] == null) {
                } else {
                    var data1 = $('#txtAmbulance').combobox('getData');  //赋默认值
                    SAmbulance = data1[1].Name;   //日报表 跟车走
                }
            }   //onLoadSuccess  end
        ,
            onSelect: function () {
                SAmbulance = $("#txtAmbulance").combobox('getText');

            }
        });

    }

    function rePickTaskGrid() {
        $('#PickTaskList').datagrid({
            pageNumber: 1,
            queryParams: {
                StartTime: $("#txtStartTime").datetimebox('getValue'),
                EndTime: $("#txtEndTime").datetimebox('getValue'),
                //Station: $("#txtStation").combobox('getValue') ? $("#txtStation").combobox('getValue') : "", //三目运算符
                ambulanceCode: $("#txtAmbulance").combobox('getValue') ? $("#txtAmbulance").combobox('getValue') : "",
                DworkID: DworkID
            }
        });
    }

    //加载列表数据
    function PickTaskGrid() {
        $('#PickTaskList').datagrid({
            height: 440,
            fitColumns: false,
            collapsible: true,
            singleSelect: false,
            selectOnCheck: true, //如果为true，单击复选框将永远选择行。
            checkOnSelect: true,  //如果为true，当用户点击行的时候该复选框就会被选中或取消选中。
            loadMsg: '数据加载中,请稍后……',
            url: '@Url.Content("~/DD/DriverReport/GetPickTask")',
            rownumbers: true,//显示页码，
            queryParams: {
                StartTime: $("#txtStartTime").datetimebox('getValue'),
                EndTime: $("#txtEndTime").datetimebox('getValue'),
                //Station: $("#txtStation").combobox('getValue') ? $("#txtStation").combobox('getValue') : "", //三目运算符
                ambulanceCode: $("#txtAmbulance").combobox('getValue') ? $("#txtAmbulance").combobox('getValue') : "",

                DworkID: DworkID
            },
            columns: [[
            { field: "ck", checkbox: true },
            { field: "TaskCode", hidden: true },
             { field: "AmbulanceCode", hidden: true },
            { field: "StationName", title: "分站", width: '5%', align: "center", sortable: false, resizable: false },
            { field: "RealAmbulanceSign", title: "车辆", width: '6%', align: "center", sortable: false, resizable: false },
              { field: "Driver", title: "司机", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "Doctor", title: "医生", width: '5%', align: "center", sortable: false, resizable: true },
              { field: "Nurse", title: "护士", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "Stretcher", title: "担架员", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "AlarmTel", title: "呼救电话", width: '8%', align: "center", sortable: false, resizable: true },
              { field: "StartTaskTime", title: "生成任务时刻", width: '12%', align: "center", formatter: $.formatTime, sortable: false, resizable: true },
            { field: "LocalAddr", title: "现场地址", width: '16%', align: "center", sortable: false, resizable: true },
            { field: "SendAddr", title: "送往地址", width: '10%', align: "center", sortable: false, resizable: true },
            { field: "PatientName", title: "患者姓名", width: '6%', align: "center", sortable: false, resizable: false },
            { field: "AlarmReason", title: "主诉", width: '8%', align: "center", sortable: false, resizable: true },
            { field: "DispatcherName", title: "责任调度员", width: '5%', align: "center", sortable: false, resizable: true },
              { field: "CompletedTime", title: "完成任务时刻", width: '8%', align: "center", sortable: false, resizable: true },

            //{ field: "EmergencyFee", title: "院前急救费", width: '6%', align: "center", sortable: false, resizable: true }, //add2021-10-14 plq 
            //{ field: "DrugFee", title: "药品费", width: '5%', align: "center", sortable: false, resizable: true },
            //{ field: "ConsumableFee", title: "材料费", width: '5%', align: "center", sortable: false, resizable: true },
            //{ field: "ExamineFee", title: "检查费", width: '5%', align: "center", sortable: false, resizable: true },
            //{ field: "MeasureFee", title: "治疗费", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "PaidPRFee", title: "医疗费", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "PaidCarFee", title: "车费", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "ReceivableTotal", title: "应收合计", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "PaidMoney", title: "实收合计", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "XJMoney", title: "现金收费", width: '5%', align: "center", sortable: false, resizable: true }, //add2021-10-14 plq 医保上线
            { field: "YBMoney", title: "医保收费", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "MLMoney", title: "分币误差", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "YLMoney", title: "银联收费", width: '5%', align: "center", sortable: false, resizable: true }, //add2022-01-13 plq 银联收费
            { field: "ZFBMoney", title: "支付宝实收", width: '5%', align: "center", sortable: false, resizable: true }, //add2022-02-07 plq
            { field: "WXMoney", title: "微信实收", width: '5%', align: "center", sortable: false, resizable: true },

            ]],
            toolbar: [
                 {
                     id: 'btnRevisitView',
                     text: '已勾选[0]个',
                     iconCls: 'icon-custom-cGoods',
                     iconWidth: 22,
                     handler: function () {
                         if (Materials.length > 0) {
                             //2016-6-7 zch 添加判断
                             if ($('#txtAmbulance').combobox('getValue') != "") {
                                 //2016-6-23 zch 增加判断是否勾选了不同车
                                 var ifsameAmb = false;
                                 $.each(Materials, function (index, mates) {
                                     if (Materials[0].RealAmbulanceSign != Materials[index].RealAmbulanceSign) {
                                         ifsameAmb = true;
                                     }
                                 });
                                 //2016-6-23 zch 增加判断是否勾选了不同车
                                 if (ifsameAmb) {
                                     $.messager.alert('提示', '您勾选了不同车辆，请重新勾选任务！', 'info', function () {
                                     });
                                 }
                                 else {
                                     $('#RevisitAddMain').dialog('open'); //打开 提交任务 弹层页
                                     RevistAddMainGrid(); //加载弹层页列表数据
                                 }
                             }
                             else {
                                 $.messager.alert('提示', '请选择车辆', 'info', function () {
                                 });
                             }
                         } else {
                             $.messager.alert('提示', '请选择任务', 'info', function () {
                             });
                         }
                     }
                 }
            ],
            onCheck: function (index, row) {

                //2016-4-16 新增当选择任务的时候，将车辆自动选中
                $('#txtAmbulance').combobox('select', row.AmbulanceCode);
                if (Materials.length == 0) {
                    Materials.push(row);
                    changeRevisitViewNum();
                    return;
                }
                var boolContain = false;
                $.each(Materials, function (i, info) {
                    if (info.TaskCode == row.TaskCode) {
                        boolContain = true;
                    }
                });
                if (!boolContain) {
                    Materials.push(row);
                }
                changeRevisitViewNum();

            },
            onUncheck: function (index, row) {
               $('#txtAmbulance').combobox('clear');
                var obj;
                $.each(Materials, function (i, info) {
                    if (info.TaskCode == row.TaskCode) {
                        obj = info;
                    }
                });
                Materials.remove(obj);
                changeRevisitViewNum();
            },
            onCheckAll: function (rows) {
                $.each(rows, function (i, infos) {
                    // var arr = ["xml", "html", "css", "js"];
                    //   $.inArray("js", arr);  //返回 3,
                    //  如果不包含在数组中, 则返回 - 1;

                    var hasmates = false;
                    $.each(Materials, function (index, mates) {
                        if (infos.TaskCode == mates.TaskCode) {
                            hasmates = true;
                        }
                    });
                    // if (Materials.indexOf(rows[ii]) < 0) {  //index用法只能用于string之间，不可以用于数组。
                    if (!hasmates)
                    { Materials.push(infos); }
                }
                );
                changeRevisitViewNum();
            },
            onUncheckAll: function (rows) {
                var obj;
                $.each(rows, function (i, infos) {
                    $.each(Materials, function (index, mates) {
                        if (infos.TaskCode == mates.TaskCode) {
                            //if ($.inArray(rows[i], Materials)>=0){
                            obj = infos;
                        }
                    });
                    Materials.remove(obj);

                    changeRevisitViewNum();
                });
            },
            onLoadSuccess: function (data) {
                var rows = $('#PickTaskList').datagrid('getRows');
                if (rows.length == 0) {
                    $.messager.alert('系统提示', '当前日期无任务，或已被全部勾选！', 'info', function () {
                    });
                }
                else {
                    $.messager.show({
                        title: '系统提示',
                        msg: '   成功加载出 ' + data.total + ' 条任务信息！'
                    });
                }
                setViewNumCheck();
                // changeDeliveryViewNum();
            }

        });
    }

    function setViewNumCheck() { //自动勾选已经存在的内容
        var rows = $('#PickTaskList').datagrid('getRows');
        $.each(rows, function (index, item) {
            $.each(Materials, function (i, info) {
                if (item.TaskCode == info.TaskCode) {
                    $('#PickTaskList').datagrid('checkRow', index);
                }
            });
        });
    }

    function changeRevisitViewNum() {
        if (Materials.length == 0) {
            $("#btnRevisitView").linkbutton({
                text: "已勾选任务[" + Materials.length + "]个",
                iconCls: "icon-custom-cGoods"
            });

            //$('#txtTaskDate').datebox('readonly', false);

        } else if (Materials.length > 0) {
            $("#btnRevisitView").linkbutton({
                text: "已勾选任务[<strong><span style='color:red'>" + Materials.length + "</span></strong>]个",
                iconCls: "icon-custom-cGoodsFull"
            });
            //$('#txtTaskDate').datebox('readonly', true);
        }
    }

    function deleteEditRowID() {
        EditRowID = "";
    }

</script>

<div id="RevisitAddTask" class="easyui-dialog" title="请选择任务" data-options="modal:true,
     collapsible:false,
     minimizable:false,
     maximizable:true,
     closed:true,
     resizable:true,
     iconCls:'icon-custom-cDelivery',
     onClose:function(){ deleteEditRowID();}" style="width: 98%; height: 520px; padding: 0px; ">
    @*<div data-options="region:'center',title:'回访',iconCls:'icon-custom-cPrice'">*@
    <div id="tbb" style="padding: 5px; height: auto">
        <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td align="right" valign="middle" width="8%">任务时间：</td>
                <td align="left" valign="middle" width="13%">
                    <input class="easyui-datetimebox" style="width:160px" id="txtStartTime" data-options="editable:false">
                </td>
                <td align="right" valign="middle" width="8%">至：</td>
                <td align="left" valign="middle" width="13%">
                    <input class="easyui-datetimebox" style="width:160px" id="txtEndTime" data-options="editable:false">
                </td>
                <td align="right" valign="middle" width="8%">出车车辆：</td>
                <td align="left" valign="middle" width="13%">
                    <input class="easyui-combobox" style="width: 110px" id="txtAmbulance">
                </td>

                <td width="12%">
                    &nbsp;&nbsp;
                    <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="PickTaskGrid()">查询</a>
                </td>
                <td></td>
            </tr>
        </table>

    </div>
    <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
        <table id="PickTaskList" border="0"></table>
    </div>
</div>
